package com.dingding.baseservice.email.impl;

import java.util.Map;

import org.apache.commons.mail.SimpleEmail;

import com.dingding.baseservice.email.IEmailSend;
import com.dingding.baseservice.email.ITemplateEmail;
import com.dingding.common.core.config.EmailConfig;

/**
 * 
 * @ClassName: SimpleMailSend 
 * @Description: 纯文本邮件发送实现
 * @author CHEHAUNBO 
 * @date 2016年1月27日 下午5:22:49
 * 
 */
public class SimpleMailSend implements IEmailSend {

	private ITemplateEmail templateEmail = null;

	/**
	 * 
	 * @Title: senMail 
	 * @Description: 邮件发送,纯文本
	 * @return void  
	 * @author CHEHAUNBO
	 * 
	 * 
	 */
	@Override
	public void senMail(Map<String, Object> titleObj, String titleName,Map<String, Object> root, String templateName) throws Exception {

		// 获取标题模板
		String title = templateEmail.getMailText(titleObj, titleName);
		// 获取内容模板
		String emailContext = templateEmail.getMailText(root, templateName);

		SimpleEmail email = new SimpleEmail();

		// smtp host
		email.setHostName(EmailConfig.getEMAIL_HOST());
		// 登陆邮件服务器的用户名和密码
		email.setAuthentication(EmailConfig.getEMAIL_OUTBOX_NAME(), EmailConfig.getEMAIL_OUTBOX_PWD());
		// 接收人
		email.addTo(EmailConfig.getINBOX());
		// 发送人
		email.setFrom(EmailConfig.getOUTBOX());
		// 标题
		email.setSubject(title);
		// 邮件内容
		email.setMsg(emailContext);
		// 发送
		email.send();

	}

	public ITemplateEmail getTemplateEmail() {
		return templateEmail;
	}

	public void setTemplateEmail(ITemplateEmail templateEmail) {
		this.templateEmail = templateEmail;
	}

}
